<?php

namespace app\admin\controller;

use think\Controller;

class Featured extends Base
{
    private $obj;

    public function _initialize()
    {
        $this->obj = model("Featured");
    }

    public function index()
    {
        // 获取推荐位类别

        $types = config('featured.featured_type');
        $type = input('get.type') ? input('get.type') : 0;
        $result = $this->obj->getFeaturedsByType($type);
        return $this->fetch('',[
            'types' => $types,
            'results' => $result,
            'type' => $type,
        ]);
    }

    public function add()
    {
        if (request()->isPost()) {
            $data = input("post.");
            $id = model('Featured')->add($data);
            if(!empty($id)){
                $this->success('添加成功');
            }else{
                $this->error("error");
            }
        } else {
            $types = config('featured.featured_type');
            return $this->fetch('', [
                'types' => $types,
            ]);
        }
    }

   public function status()
   {    //id,status
        $data = input('get.');
        $res= $this->obj->save(['status'=>$data['status']],['id'=>$data['id']]);
        if($res){
            $this->success("更新成功");
        }else{
            $this->error("更新失败");
        }
   }
}
